package com.xingu.xg.controller;

import com.xingu.xg.common.consts.ComResult;
import com.xingu.xg.domain.XgMenu;
import com.xingu.xg.service.XgMenuService;
import com.xingu.xg.valid.AddNodeGroup;
import com.xingu.xg.valid.CopyNodeGroup;
import com.xingu.xg.vo.AddNodeQuery;
import com.xingu.xg.vo.CopyNodeQuery;
import com.xingu.xg.vo.DeleteNodeQuery;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (XgMenu)表控制层
 *
 * @author L
 * @since 2024-05-16 00:04:19
 */
@RestController
@RequestMapping("xgMenu")
public class XgMenuController {
    /**
     * 服务对象
     */
    @Resource
    private XgMenuService xgMenuService;


    @PostMapping("add")
    public ComResult add(@RequestBody XgMenu xgMenu){
        return xgMenuService.add(xgMenu);
    }
    /**
     * 根据项目id查询所有下级项目
     */
    @PostMapping("query")
    public ComResult<XgMenu> queryAllByProjectId(@RequestBody @Validated AddNodeQuery addNodeQuery) {
        return this.xgMenuService.queryAllByProjectId(addNodeQuery.getSelectedId());
    }

    @PostMapping("addNode")
    public ComResult addNode(@RequestBody @Validated({AddNodeGroup.class}) AddNodeQuery addNodeQuery){
        return xgMenuService.addNode(addNodeQuery);
    }

    @PostMapping("copyNode")
    public ComResult copyNode(@RequestBody @Validated(CopyNodeGroup.class) CopyNodeQuery copyNodeQuery){
        return xgMenuService.copyNode(copyNodeQuery);
    }

    @PostMapping("deleteNode")
    public ComResult deleteNode(@RequestBody DeleteNodeQuery deleteNodeQuery){
        return xgMenuService.deleteNode(deleteNodeQuery);
    }

}


